/* 
 * Copyright 2012 Mikaël GUILLEMOT
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.g2de.gui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

/**
 * Boutton a texte
 * 
 * @author Mikael GUILLEMOT
 * @version 1.0
 * @since
 * 
 */
public class UITxtBoutton extends UIPicBoutton {

	private int w, h, txtw;

	/**
	 * cree un boutton a partire d'une taille de base et d'une chaine. Si la
	 * chaine est trop grande, ou que la base n'est pas fournie le boutton est
	 * elargie, sinon la chaine est centrée
	 * 
	 * @param r
	 * @param label
	 */
	public UITxtBoutton(int width, int height, String label, Color base, Color over) {
		super(null, null);
		// TODO adapter ca a la police
		// on determine la taille du boutton
		h = 16;
		w = 10 * label.length();
		txtw = 0;
		if (height > h)
			h = height;
		if (width > w) {
			txtw = (width - w) / 2;
			w = width;
		}
		// pour aller vite on gere des image généré ici
		BufferedImage tmp = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
		Graphics g = tmp.getGraphics();
		g.setColor(base);
		g.fillRect(0, 0, w, h);
		g.setColor(Color.BLACK);
		g.drawString(label, txtw, 0);
		g.drawRect(0, 0, w, h);
		setPic(tmp);
		tmp = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
		g = tmp.getGraphics();
		g.setColor(over);
		g.fillRect(0, 0, w, h);
		g.setColor(Color.BLACK);
		g.drawString(label, txtw, 0);
		g.drawRect(0, 0, w, h);
		setActivePic(tmp);
	}

}
